/*
	extract the sql command and other metadata for old sleeping processes
	bw - 7/24/2007
*/

USE				[master]
GO

SELECT			[spid],
				SYS.[dbid],
				[cpu],
				[physical_io],
				[login_time],
				[last_batch],
				[text] as 'command'
FROM			[sysprocesses] SYS
OUTER APPLY		::fn_get_sql(SYS.sql_handle)
WHERE			[spid] > 50										-- ignore system processes
AND				[last_batch] < DATEADD(hh, -1, GETDATE())		-- more than 
AND				[status] = 'sleeping'


/* filter by host or login */
--AND				[loginame] IN ('valeriuser')
--AND				[hostname] IN ('bwoodringxpfl')
